package com.vincent.template.commons.base;

import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.Column;
import javax.persistence.EntityListeners;
import javax.persistence.MappedSuperclass;
import javax.persistence.Version;
import java.util.Date;

/**
 * @author Vincent Wang
 * @date 2021/3/24 22:58
 */
@MappedSuperclass
@EntityListeners(AuditingEntityListener.class)
public abstract class BaseFieldPart {

    @Column(updatable = false)
    @CreatedDate
    private Date createTime;

    @Column(insertable = false)
    @LastModifiedDate
    private Date updateTime;

    @Column(columnDefinition = "tinyint(1) default 0", insertable = false)
    private boolean deleted;

    @Column
    @Version
    private Long version;

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Date getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(Date updateTime) {
        this.updateTime = updateTime;
    }

    public boolean isDeleted() {
        return deleted;
    }

    public void setDeleted(boolean deleted) {
        this.deleted = deleted;
    }

    public Long getVersion() {
        return version;
    }

    public void setVersion(Long version) {
        this.version = version;
    }
}
